package com.videoplayer;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableContainer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.adapter.NavAdapter;
import com.entity.Navigation;

public class LeftFragment extends Fragment {

	public ListView lvNavigation;
	public NavAdapter navAdapter;
	public List<Navigation> list = new ArrayList<Navigation>();
	private ChangeList change;
	
	public interface ChangeList{
		public void Change(String url);
	}
	
	

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		change = (ChangeList)activity;
	}



	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.left, null);
		lvNavigation = (ListView) view.findViewById(R.id.lv_nav);
		Navigation youku = new Navigation("优酷", "http://www.youku.com",
				getActivity().getResources().getDrawable(R.drawable.youku));
		Navigation tudou = new Navigation("腾讯", "http://v.qq.com/",
				getActivity().getResources().getDrawable(R.drawable.tecent));
		Navigation tudou2 = new Navigation("播放记录", "history",
				getActivity().getResources().getDrawable(R.drawable.history));
		Navigation tudou3 = new Navigation("搜索", "search",
				getActivity().getResources().getDrawable(R.drawable.search));
//		Navigation tudou4 = new Navigation("土豆", "http://www.tudou.com",
//				getActivity().getResources().getDrawable(R.drawable.tudou));
		list.add(youku);
		list.add(tudou);
		list.add(tudou2);
		list.add(tudou3);
		navAdapter = new NavAdapter(getActivity(),list);
		lvNavigation.setAdapter(navAdapter);
		lvNavigation.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				navAdapter.setFlag(arg2);
				navAdapter.notifyDataSetChanged();
				change.Change(list.get(arg2).getId());
				((MainActivity) getActivity()).showLeft();
			}
		});
//		navAdapter.getItem(0).
		return view;
	}
	
	

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

}
